home *** CD-ROM | disk | FTP | other *** search
- ;void pad_right(strg,ch,length);
- ; unsigned char *strg,ch;
- ; unsigned short length;
-
- EXTRN _memory_model:byte
- EXTRN _error_code:byte
-
- _TEXT SEGMENT BYTE PUBLIC 'CODE'
- ASSUME CS:_TEXT
- PUBLIC _pad_right
- _pad_right proc near
- push bp ;
- mov bp,sp ;set up stack frame
- push di ;
- cmp _memory_model,0 ;near or far?
- jle begin ;jump if near
- inc bp ;else add 2 to BP
- inc bp ;
- begin: mov _error_code,1 ;1 = error
- cmp _memory_model,2 ;data near or far?
- jb L0 ;jump if near
- les di,dword ptr[bp+4] ;get string address
- inc bp ;add 2 to BP since dword ptr
- inc bp ;
- jmp short L1 ;jump ahead
- L0: mov di,[bp+4] ;near case
- mov ax,ds ;ES = DS
- mov es,ax ;
- L1: mov si,di ;copy ptr start position
- L2: cmp byte ptr es:[di],0 ;move DI to end of string
- je L3 ;
- inc di ;
- jmp short L2 ;
- L3: mov cx,di ;counter
- sub cx,si ;string length
- sub bx,bx ;
- mov bl,[bp+8] ;new string length
- cmp cl,bl ;compare the two lengths
- jae L4 ;quit if old len>=new len
- sub bx,cx ;bx = number pad chars to write
- mov cx,bx ;use as counter
- mov al,[bp+6] ;get pad character
- cld ;direction forward
- rep stosb ;write the pad characters
- mov byte ptr es:[di],0 ;add terminator
- dec _error_code ;0 = no error
- L4: pop di ;
- pop bp ;
- cmp _memory_model,0 ;quit
- jle quit ;
- db 0CBh ;RET far
- quit: ret ;RET near
- _pad_right ENDP
- _TEXT ENDS
- END